﻿<UserControl x:Class="GEPL.StandardModulesLibrary.Views.Common.LoopView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:p="clr-namespace:GEPL.StandardModulesLibrary.Properties"
             xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
             xmlns:converters="clr-namespace:GEPL.StandardModulesLibrary.Converters"
             xmlns:vm="clr-namespace:GEPL.StandardModulesLibrary.ViewModels.Common"
             mc:Ignorable="d"
             Height="200"
             Width="200"
             d:DataContext="{d:DesignInstance vm:LoopViewModel}">
    <UserControl.Resources>
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
        <converters:NegBoolToVisibilityConverter x:Key="NegBoolToVisibilityConverter" />
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <StackPanel Grid.Row="0"
                    VerticalAlignment="Center">
            <RadioButton Content="{x:Static p:Resources.Loop_ForLoop}"
                         IsChecked="{Binding ForLoop, Mode=TwoWay}" />
            <RadioButton Content="{x:Static p:Resources.Loop_WhileDoLoop}"
                         IsChecked="{Binding WhileLoop, Mode=TwoWay}" />
            <RadioButton Content="{x:Static p:Resources.Loop_DoWhileLoop}"
                         IsChecked="{Binding DoWhileLoop,Mode=TwoWay}" />
        </StackPanel>
        <Grid Grid.Row="1"
              Visibility="{Binding IsEnd,Converter={StaticResource NegBoolToVisibilityConverter}}">
            <Grid Visibility="{Binding ForLoop, Converter={StaticResource BooleanToVisibilityConverter}}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Label Content="{x:Static p:Resources.ForLoop_For}"
                       Margin="0,5"
                       Grid.Column="0"
                       Grid.Row="1" />
                <TextBox Grid.Row="1"
                         Grid.Column="1"
                         Margin="0,5"
                         Text="{Binding Variable, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                <Label Content="{x:Static p:Resources.ForLoop_InRange}"
                       Grid.Column="0"
                       Grid.Row="2"
                       Margin="0,5" />
                <StackPanel Orientation="Horizontal"
                            Grid.Column="1"
                            Grid.Row="2">
                    <xctk:IntegerUpDown Value="{Binding RangeFrom}" />
                    <Label Content="{x:Static p:Resources.ForLoop_Range_To}" />
                    <xctk:IntegerUpDown Value="{Binding RangeTo}" />
                </StackPanel>
                <TextBlock Text="{x:Static p:Resources.Loop_Repeat}"
                           Grid.Row="3"
                           Grid.ColumnSpan="2" />
            </Grid>
            <Grid Visibility="{Binding WhileLoop, Converter={StaticResource BooleanToVisibilityConverter}}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="*" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <TextBlock Text="{x:Static p:Resources.Loop_While}"
                           Grid.Row="1"
                           Grid.Column="0"
                           Grid.ColumnSpan="2" />
                <Label Grid.Column="0"
                   Grid.Row="2"
                   Content="{x:Static p:Resources.Miscs_Value}" />
                <TextBox Grid.Column="1"
                     Grid.Row="2"
                     Text="{Binding WhileConditionValue1, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                <ComboBox Grid.Column="0"
                      Grid.Row="3"
                      ItemsSource="{Binding ConditionsList, Mode=OneWay}"
                      SelectedValue="{Binding SelectedWhileCondition, Mode=TwoWay}"
                      DisplayMemberPath="Value"
                      SelectedValuePath="Key" />
                <TextBox Grid.Column="1"
                     Grid.Row="3"
                     Text="{Binding WhileConditionValue2, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                <TextBlock Text="{x:Static p:Resources.Loop_Repeat}"
                           Grid.Row="4"
                           Grid.ColumnSpan="2" />
            </Grid>
        </Grid>
        <Grid Visibility="{Binding DoWhileLoop, Converter={StaticResource BooleanToVisibilityConverter}}"
              Grid.Row="1">
            <Grid Visibility="{Binding IsEnd, Converter={StaticResource BooleanToVisibilityConverter}}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="*" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <TextBlock Text="{x:Static p:Resources.Loop_While}"
                           Grid.Row="1"
                           Grid.Column="0"
                           Grid.ColumnSpan="2" />
                <Label Grid.Column="0"
                   Grid.Row="2"
                   Content="{x:Static p:Resources.Miscs_Value}" />
                <TextBox Grid.Column="1"
                     Grid.Row="2"
                     Text="{Binding WhileConditionValue1, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                <ComboBox Grid.Column="0"
                      Grid.Row="3"
                      ItemsSource="{Binding ConditionsList, Mode=OneWay}"
                      SelectedValue="{Binding SelectedWhileCondition, Mode=TwoWay}"
                      DisplayMemberPath="Value"
                      SelectedValuePath="Key" />
                <TextBox Grid.Column="1"
                     Grid.Row="3"
                     Text="{Binding WhileConditionValue2, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
            </Grid>
            <Grid Visibility="{Binding IsEnd, Converter={StaticResource NegBoolToVisibilityConverter}}">
                <TextBlock Text="{x:Static p:Resources.Loop_Repeat}"
                           VerticalAlignment="Center" />
            </Grid>
        </Grid>
        <CheckBox Content="{x:Static p:Resources.ForLoop_End}"
                  IsChecked="{Binding IsEnd, Mode=TwoWay}"
                  Grid.Column="0"
                  Grid.Row="2"
                  Margin="0,5" />
    </Grid>
</UserControl>